<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core" 
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:p="http://primefaces.org/ui">
    <ui:composition template="/template.xhtml">
        <ui:define name ="title">
            <h:outputText value="Welcome to BrainStretch"/>
        </ui:define>
        <ui:define name ="body">
        
        <h:panelGroup rendered="#{quizController.quiz != null}">
        <SCRIPT src="http://java.com/js/dtjava.js"></SCRIPT>
        <script>
            function launchApplication(jnlpfile) {
                dtjava.launch(            {
                        url : 'app/QuizApp.jnlp',
                        params: { 'quizId': '#{param['quizId']}', 'serviceURI':'http://localhost:8080/BrainStretch-war/resources/quiz'} 
                    },
                    {
                        javafx : '2.0+'
                    },
                    {}
                );
                return false;
            }
        </script>
        <script>
            var app = new dtjava.App(
                'app/QuizApp.jnlp',
                    {
                        id: 'quizApp',
                        width: 800,
                        height: 600,
                        params: { 'user':'#{userController.user.name}', 'quizId': '#{param['quizId']}', 'serviceURI':'http://localhost:8080/BrainStretch-war/resources/quiz'},
                        placeholder:'javafx-app-placeholder'                          
                    }
            );
            function javafxEmbed() {
                dtjava.embed(
                    app, {javafx : '2.0+'},{}
                );
            }
            dtjava.addOnloadCallback(javafxEmbed);
        </script>
        <h2>#{quizController.quiz.title}</h2>
        <div id='javafx-app-placeholder' class="centeredMargin"></div>
        </h:panelGroup>
        <h:panelGrid rendered="#{quizController.quiz == null}">
            <p:messages/>
        </h:panelGrid>
            <h:form>
            <ui:repeat value="#{recommendationController.recommended}" var="rec">
                <h:outputText value="#{rec.title}"/>
                <h:commandButton value="reject" action="#{recommendationController.turnDownRecommended(rec)}">
                    <p:ajax execute="@form" update="@form"/>
                </h:commandButton>
                <br/>
            </ui:repeat>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
